home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1999 #2 / Amiga Plus CD - 1999 - No. 2.iso / System-Boost / Workbench / ToolManager / Source / Library / commands.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  4KB  |  161 lines

  1. /*
  2.  * commands.c  V3.1
  3.  *
  4.  * ToolManager IPC command handling routines
  5.  *
  6.  * Copyright (C) 1990-98 Stefan Becker
  7.  *
  8.  * This source code is for educational purposes only. You may study it
  9.  * and copy ideas or algorithms from it for your own projects. It is
  10.  * not allowed to use any of the source codes (in full or in parts)
  11.  * in other programs. Especially it is not allowed to create variants
  12.  * of ToolManager or ToolManager-like programs from this source code.
  13.  *
  14.  */
  15.  
  16. #include "toolmanager.h"
  17.  
  18. /* Local data */
  19. static struct MsgPort *IPCPort;
  20.  
  21. /* Start IPC */
  22. #define DEBUGFUNCTION StartIPC
  23. LONG StartIPC(void)
  24. {
  25.  LONG rc = -1;
  26.  
  27.  COMMANDS_LOG(LOG0(Entry))
  28.  
  29.  /* Allocate message port */
  30.  if (IPCPort = CreateMsgPort()) rc = IPCPort->mp_SigBit;
  31.  
  32.  COMMANDS_LOG(LOG2(Result, "Port 0x%08lx Signal %ld", IPCPort, rc))
  33.  
  34.  return(rc);
  35. }
  36.  
  37. /* Stop IPC */
  38. #undef  DEBUGFUNCTION
  39. #define DEBUGFUNCTION StopIPC
  40. void StopIPC(void)
  41. {
  42.  COMMANDS_LOG(LOG1(Port, "0x%08lx", IPCPort))
  43.  
  44.  SafeDeleteMsgPort(IPCPort);
  45. }
  46.  
  47. /* Get IPC Port */
  48. struct MsgPort *GetIPCPort(void)
  49. {
  50.  return(IPCPort);
  51. }
  52.  
  53. /* Handle one IPC command */
  54. #undef  DEBUGFUNCTION
  55. #define DEBUGFUNCTION HandleIPC
  56. void HandleIPC(void)
  57. {
  58.  struct TMHandle *tmh;
  59.  
  60.  COMMANDS_LOG(LOG0(Entry))
  61.  
  62.  /* Empty IPC port message queue */
  63.  while (tmh = (struct TMHandle *) GetMsg(IPCPort)) {
  64.  
  65.   COMMANDS_LOG(LOG1(Command, "%ld", tmh->tmh_Message.tmm_Command))
  66.  
  67.   /* What command did we receive? */
  68.   switch (tmh->tmh_Message.tmm_Command) {
  69.    case TMIPC_AllocTMHandle:
  70.     tmh->tmh_Message.tmm_Command = InitToolManagerHandle(tmh);
  71.     break;
  72.  
  73.    case TMIPC_FreeTMHandle:
  74.     DeleteToolManagerHandle(tmh);
  75.     tmh->tmh_Message.tmm_Command = TRUE;
  76.     break;
  77.  
  78.    case TMIPC_CreateTMObject: {
  79.      Object *obj;
  80.  
  81.      COMMANDS_LOG(LOG2(Create, "Name '%s' Type %ld",
  82.                        tmh->tmh_Message.tmm_Object, tmh->tmh_Message.tmm_Type))
  83.  
  84.      /* Set error return code */
  85.      tmh->tmh_Message.tmm_Command = FALSE;
  86.  
  87.      /* Create new object */
  88.      if (obj = CreateToolManagerObject(tmh, tmh->tmh_Message.tmm_Type)) {
  89.  
  90.       COMMANDS_LOG((LOG2(Created, "Object 0x%08lx Tags 0x%08lx",
  91.                          obj, tmh->tmh_Message.tmm_Tags),
  92.                     PrintTagList(tmh->tmh_Message.tmm_Tags)))
  93.  
  94.       /* Set object name */
  95.       SetAttrs(obj, TMA_ObjectName, tmh->tmh_Message.tmm_Object, TAG_DONE);
  96.  
  97.       /* Set Object name and initialize object with tag list */
  98.       if (DoMethod(obj, TMM_ParseTags, tmh->tmh_Message.tmm_Tags))
  99.  
  100.        /* Object created */
  101.        tmh->tmh_Message.tmm_Command = TRUE;
  102.  
  103.       else
  104.  
  105.        /* Error in tag list */
  106.        DisposeObject(obj);
  107.      }
  108.     }
  109.     break;
  110.  
  111.    case TMIPC_DeleteTMObject: {
  112.      struct Object *obj;
  113.  
  114.      COMMANDS_LOG(LOG1(Delete, "'%s'", tmh->tmh_Message.tmm_Object))
  115.  
  116.      /* Set error return code */
  117.      tmh->tmh_Message.tmm_Command = FALSE;
  118.  
  119.      /* Search object */
  120.      if (obj = FindNamedTMObject(tmh, tmh->tmh_Message.tmm_Object)) {
  121.  
  122.       COMMANDS_LOG(LOG1(Deleting, "0x%08lx", tmh->tmh_Message.tmm_Object))
  123.  
  124.       /* Dispose object */
  125.       DisposeObject(obj);
  126.       tmh->tmh_Message.tmm_Command = TRUE;
  127.      }
  128.     }
  129.     break;
  130.  
  131.    case TMIPC_ChangeTMObject: {
  132.      struct Object *obj;
  133.  
  134.      COMMANDS_LOG(LOG1(Change, "'%s'", tmh->tmh_Message.tmm_Object))
  135.  
  136.      /* Set error return code */
  137.      tmh->tmh_Message.tmm_Command = FALSE;
  138.  
  139.      /* Search object */
  140.      if (obj = FindNamedTMObject(tmh, tmh->tmh_Message.tmm_Object)) {
  141.  
  142.       COMMANDS_LOG((LOG2(Changing, "Object 0x%08lx Tags 0x%08lx",
  143.                          tmh->tmh_Message.tmm_Object,
  144.                          tmh->tmh_Message.tmm_Tags),
  145.                     PrintTagList(tmh->tmh_Message.tmm_Tags)))
  146.  
  147.       /* Change object */
  148.       tmh->tmh_Message.tmm_Command = DoMethod(obj, TMM_ParseTags,
  149.                                               tmh->tmh_Message.tmm_Tags);
  150.      }
  151.     }
  152.     break;
  153.   }
  154.  
  155.   COMMANDS_LOG(LOG1(Command reply, "%ld", tmh->tmh_Message.tmm_Command))
  156.  
  157.   /* Reply message */
  158.   ReplyMsg((struct Message *) tmh);
  159.  }
  160. }
  161.